home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / rcs5ap1s.lzh / IDENT.C < prev    next >
C/C++ Source or Header  |  1991-01-30  |  5KB  |  196 lines

  1. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  2.    Copyright 1990 by Paul Eggert
  3.    Distributed under license by the Free Software Foundation, Inc.
  4.  
  5. This file is part of RCS.
  6.  
  7. RCS is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. RCS is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with RCS; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21. Report problems and direct all questions to:
  22.  
  23.     rcs-bugs@cs.purdue.edu
  24.  
  25. */
  26.  
  27. /*
  28.  *                     RCS identification operation
  29.  */
  30.  
  31. /* $Log: ident.c,v $
  32.  * Revision 5.1  1991/01/30  14:21:32  apratt
  33.  * CI with RCS version 5
  34.  *
  35.  * Revision 5.0  90/08/22  08:12:37  eggert
  36.  * checked in with -k by apratt at 91.01.10.13.14.54.
  37.  * 
  38.  * Revision 5.0  1990/08/22  08:12:37  eggert
  39.  * Don't limit output to known keywords.
  40.  * Remove arbitrary limits and lint.  Ansify and Posixate.
  41.  *
  42.  * Revision 4.5  89/05/01  15:11:54  narten
  43.  * changed copyright header to reflect current distribution rules
  44.  * 
  45.  * Revision 4.4  87/10/23  17:09:57  narten
  46.  * added exit(0) so exit return code would be non random
  47.  * 
  48.  * Revision 4.3  87/10/18  10:23:55  narten
  49.  * Updating version numbers. Changes relative to 1.1 are actually relative
  50.  * to 4.1
  51.  * 
  52.  * Revision 1.3  87/07/09  09:20:52  trinkle
  53.  * Added check to make sure there is at least one arg before comparing argv[1]
  54.  * with "-q".  This necessary on machines that don't allow dereferncing null
  55.  * pointers (i.e. Suns).
  56.  * 
  57.  * Revision 1.2  87/03/27  14:21:47  jenkins
  58.  * Port to suns
  59.  * 
  60.  * Revision 4.1  83/05/10  16:31:02  wft
  61.  * Added option -q and input from reading stdin.
  62.  * Marker matching is now done with trymatch() (independent of keywords).
  63.  * 
  64.  * Revision 3.4  83/02/18  17:37:49  wft
  65.  * removed printing of new line after last file.
  66.  *
  67.  * Revision 3.3  82/12/04  12:48:55  wft
  68.  * Added LOCKER.
  69.  *
  70.  * Revision 3.2  82/11/28  18:24:17  wft
  71.  * removed Suffix; added ungetc to avoid skipping over trailing KDELIM.
  72.  *
  73.  * Revision 3.1  82/10/13  15:58:51  wft
  74.  * fixed type of variables receiving from getc() (char-->int).
  75. */
  76.  
  77. #include  "rcsbase.h"
  78.  
  79. static int match P((FILE*));
  80. static int scanfile P((FILE*));
  81.  
  82. mainProg(identId, "ident", "$Id: ident.c,v 5.1 1991/01/30 14:21:32 apratt Exp $")
  83. /*  Ident searches the named files for all occurrences
  84.  *  of the pattern $keyword:...$, where the keywords are
  85.  *  Author, Date, Header, Id, Log, RCSfile, Revision, Source, and State.
  86.  */
  87.  
  88. {
  89.    FILE *fp;
  90.    int quiet;
  91.    int status = EXIT_SUCCESS;
  92.  
  93.    if ((quiet  =  argc > 1 && strcmp("-q",argv[1])==0)) {
  94.         argc--; argv++;
  95.    }
  96.  
  97.    if (argc<2) {
  98.      if ((scanfile(stdin) == 0) && !quiet)
  99.         VOID fprintf(stderr, "%s warning: no id keywords in input\n", cmdid);
  100.     exitmain(EXIT_FAILURE);
  101.    }
  102.  
  103.    while ( --argc > 0 ) {
  104.       if ( (fp = fopen(*++argv, "r") ) == NULL ) {
  105.      VOID fprintf(stderr,  "%s error: can't open %s\n", cmdid, *argv);
  106.      status = EXIT_FAILURE;
  107.          continue;
  108.       } else {
  109.          VOID printf( "%s:\n", *argv);   /*  print file name  */
  110.      if ((scanfile(fp) == 0) && !quiet)
  111.         VOID fprintf(stderr, "%s warning: no id keywords in %s\n", cmdid, *argv);
  112.      if (argc>1) VOID putchar('\n');
  113.      VOID fclose(fp);
  114.       }
  115.    }
  116.    exitmain(status);
  117. }
  118.  
  119. #if lint
  120. #    define exiterr identExit
  121. #endif
  122.     exiting void
  123. exiterr()
  124. {
  125.     _exit(EXIT_FAILURE);
  126. }
  127.  
  128.  
  129.     static int
  130. scanfile(file)
  131.     register FILE *file;
  132. /* Function: scan an open file with descriptor file for keywords.
  133.  * Returns nonzero if a match is found.
  134.  */
  135. {
  136.    register int matched;
  137.    register int c;
  138.  
  139.  
  140.    matched = false;
  141.    c = 0;
  142.    while (c != EOF) {
  143.       if (c == KDELIM) {
  144.      if ((c = match(file)))
  145.         continue;
  146.      matched = true;
  147.       }
  148.       c = getc(file);
  149.    }
  150.    return matched;
  151. }
  152.  
  153.  
  154.  
  155.     static int
  156. match(fp)   /* group substring between two KDELIM's; then do pattern match */
  157.    register FILE *fp;
  158. {
  159.    char line[BUFSIZ];
  160.    register int c;
  161.    register char * tp;
  162.  
  163.    tp = line;
  164.    while ((c = getc(fp)) != VDELIM)
  165.       switch (ctab[c]) {
  166.      case LETTER: case Letter:
  167.         *tp++ = c;
  168.         if (tp < line+sizeof(line)-4)
  169.            break;
  170.         /* fall into */
  171.      default:
  172.         return c ? c : '\n'/* anything but 0 or KDELIM or EOF */;
  173.       }
  174.    *tp++ = c;
  175.    if ((c = getc(fp)) != ' ')
  176.       return c ? c : '\n';
  177.    *tp++ = c;
  178.    while( (c = getc(fp)) != KDELIM ) {
  179.       switch (ctab[c]) {
  180.      default:
  181.         *tp++ = c;
  182.         if (tp < line+sizeof(line)-2)
  183.            break;
  184.         /* fall into */
  185.      case EOFILE: case NEWLN: case UNKN:
  186.         return c ? c : '\n';
  187.       }
  188.    }
  189.    if (tp[-1] != ' ')
  190.       return tp[-1];
  191.    *tp++ = c;     /*append trailing KDELIM*/
  192.    *tp   = '\0';
  193.    VOID fprintf(stdout, "     %c%s\n", KDELIM, line);
  194.    return 0;
  195. }
  196.